
Rem
bbdoc: Health component.
endrem
Type THealthComponent Extends TComponent {expose hidefields}

	Rem
	bbdoc: Current health value.
	endrem
	Field _health:Float
	
	Rem
	bbdoc: Original health value (100%)
	endrem
	Field _maxHealth:Float
	
	
	
	Rem
	bbdoc: Constructor.
	endrem
	Function Create:THealthComponent(health:Float) {hidden}
		Local h:THealth = New THealthComponent
		h.SetHealth(health)
		Return h
	End Function

	
	
	Rem
	bbdoc: Subtracts specified amount from current health.
	endrem
	Method AddDamage(d:Float)
		_health:- d
		If _health < 0 Then _health = 0
	End Method
	
	
	
	Rem
	bbdoc: Returns true if current health > 0.
	endrem
	Method IsAlive:Int() {bool}
		Return _health > 0
	End Method
	
	
	
	Rem
	bbdoc: Returns current health value
	endrem
	Method GetHealth:Float()
		Return _health
	End Method
	
	
	
	Rem
	bbdoc: Sets the max and current health values.
	endrem
	Method SetHealth(v:Float)
		_health = v
		_maxHealth = v
	End Method
	
	
	
	Rem
	bbdoc: Returns health percentage.
	endrem	
	Method GetHealthPercentage:Int()
		Return (_health / _maxHealth) * 100
	End Method
	
End Type
